package com.lpf.zerocopy;

import java.io.FileInputStream;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class NewIOClient {

    public static void main(String[] arg) throws Exception {

        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost", 8899));
        socketChannel.configureBlocking(true);

        String fileName = "D:\\jarS\\hadoop-2.7.2.zip";

        FileChannel fileChannel = new FileInputStream(fileName).getChannel();

        //System.out.println(fileChannel.size());

        long startTime = System.currentTimeMillis();

        long transCount = fileChannel.transferTo(0, fileChannel.size(), socketChannel);

        System.out.println("发送总字节数：" + transCount + " 耗时：" + (System.currentTimeMillis() - startTime));

        fileChannel.close();

    }
}
